
package vm.project;

import java.util.Calendar;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;


public class VMProject {

    public static void main(String[] args) {
        try {
            new VMProject(args);
        } catch (Exception ex) {
            Logger.getLogger(VMProject.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public VMProject(String[] args) throws Exception{
        String fichierSortie = "test" ;
        String fichierCSV = "projetData/data.csv";
        
        if(args.length>0){
             fichierSortie=args[0];
        }

        System.out.println("Debut de l'extrapolation");
        GestionStations stations = new GestionStations();
        stations.lireFichierXLS("projetData/FichierDesSitesDeAirRhoneAlpes.xls");
        stations.initFiltre("projetData/correspondances.txt");

        double startX = stations.getXMin();
        double finalX= stations.getXMax();
        double pasX=(finalX-startX)/256.0;
        double startY=stations.getYMin();
        double finalY=stations.getYMax();
        double pasY=(finalY-startY)/256.0;   

        GestionaireGestionnaire gg = new GestionaireGestionnaire();
        for(int i=1;i<10;i++){
            Donnees d = new Donnees();
            GestionPoints gestionPoint = new GestionPoints(d.lireCSV(fichierCSV,stations,i));
            gestionPoint.extrapol(startX, finalX, pasX, startY, finalY, pasY);
            gestionPoint.setNom(fichierSortie+i);
            gg.addGestionaire(gestionPoint);
        }
        
            gg.sauvegarderDat();
            gg.sauvegarderImg();

            GestionKML2 gKML = new GestionKML2("test");
            Calendar debut = Calendar.getInstance();
            debut.setTime(new Date(0));
            Calendar fin = Calendar.getInstance();
            fin.setTime(new Date(0));
            fin.add(Calendar.HOUR, 1);
            gKML.newFolder("racine");
            for(GestionPoints gp : gg.listGestionaire){
                gKML.newFolder(gp.getNom());
                gKML.groundOverlay(gp.getNom()+"Image","c'est un test",gp.getURLImg(),finalY,startY,startX,finalX);
                gKML.afficherTouteLesPoints(gp.tabInitial, gp.getNom()+"points");
                gKML.addTimeStand(debut.getTime(), fin.getTime());
                
                    gKML.newFolder("isoValeur");
                    double ecart = gp.getVMax() - gp.getVMin();
                    for(double t=gg.getVMin();t<gg.getVMax();t+=ecart/10){
                        gKML.isoValeur("test"+t, new Marshing().calcul(gp.extrapol, t));
                    }
                    gKML.closeFolder();
                gKML.closeFolder();
                
                debut.add(Calendar.HOUR, 1);
                fin.add(Calendar.HOUR, 1);
            }
            
            gKML.afficherTouteLesSations(stations.listeStations.values(), gg.get(0).getNom()+"stations");
            gKML.marshal("florian");
        
    } 
}

